<template>
  <div class="body-wrapper">

    <!--    查询部分 -->
    <div class="search-box">
      <el-form :inline="true" class="demo-form-inline" size="mini">
        <el-form-item label="权限名称">
          <el-input v-model="searchForm.menuTitle" placeholder="请输入权限名称"></el-input>
        </el-form-item>
        <el-form-item label="权限类型">
          <el-select v-model="searchForm.menuType" placeholder="请选择权限类型">
            <el-option label="目录" :value="0"/>
            <el-option label="菜单" :value="1"/>
            <el-option label="按钮" :value="2"/>
          </el-select>
        </el-form-item>
        <el-date-picker
            v-model="value2"
            size="mini"
            type="datetimerange"
            :picker-options="pickerOptions"
            value-format="yyyy-MM-dd HH:mm:ss"
            range-separator="至"
            @change="chooseTime"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            align="left">
        </el-date-picker>

        <el-form-item style="margin-left: 10px">
          <el-button type="primary" @click="searchPage">查询</el-button>
          <el-button type="warning" @click="resetSearchForm">重置</el-button>
        </el-form-item>
      </el-form>

    </div>
    <!--    操作部分 -->
    <div class="exec-box">
      <el-button v-has-perm="['sys:menu:add']" size="mini" type="success" icon="el-icon-share"
                 @click="editDialog=true,formData={menuType: 0, parentId:0}">新建
      </el-button>
      <el-button  v-has-perm="['sys:menu:update']" size="mini" type="warning" icon="el-icon-edit" @click="findById(ids[0]),editDialog=true"
                 :disabled="ids.length!=1">修改
      </el-button>
      <el-button v-has-perm="['sys:menu:delete']" size="mini" type="danger" icon="el-icon-delete" @click="doBatchDelete" :disabled="ids.length==0">删除
      </el-button>
    </div>


    <el-scrollbar>
      <!--    列表部分 -->
      <el-table
          :data="tableData"
          row-key="id"
          stripe
          ref="table"
          highlight-current-row
          @row-click="selectChange"
          :tree-props="{children: 'children'}"
          style="width: 100%">

        <el-table-column
            prop="menuTitle"
            label="权限名称"
        >
        </el-table-column>
        <el-table-column
            prop="menuIcon"
            align="center"
            label="权限图标"
        >
          <template v-slot="obj">
            <e-icon :icon-name="obj.row.menuIcon"/>
          </template>
        </el-table-column>
        <el-table-column
            prop="sort"
            align="center"
            label="排序"
        >
          <template v-slot="obj">
            <a :href="obj.row.brandSite" target="_blank">{{ obj.row.brandName + '站点' }}</a>
          </template>
        </el-table-column>

        <el-table-column
            prop="routerPath"
            align="center"
            label="路由地址"
        >
        </el-table-column>

        <el-table-column
            prop="component"
            align="center"
            label="组件地址"
        >
        </el-table-column>

        <el-table-column
            prop="permSign"
            align="center"
            label="权限标识"
        >
        </el-table-column>
        <el-table-column
            prop="menuType"
            align="center"
            label="权限类型"
        >
          <template v-slot="obj">
            <el-tag v-if="obj.row.menuType==0">目录</el-tag>
            <el-tag v-if="obj.row.menuType==1" type="success">菜单</el-tag>
            <el-tag v-if="obj.row.menuType==2" type="warning">按钮</el-tag>
          </template>
        </el-table-column>

        <el-table-column
            prop="address"
            align="center">
          <template v-slot="obj">
            <el-button size="mini" type="primary" icon="el-icon-edit" style="margin-right: 10px"
                       v-has-perm="['sys:menu:update']"      @click.native.stop="findById(obj.row.id),editDialog=true"></el-button>


            <el-popconfirm
                v-has-perm="['sys:menu:delete']"
                confirm-button-text='好的'
                cancel-button-text='不用了'
                @confirm="batchDelete"
                @cancel="batchDeleteCancel"
                icon="el-icon-info"
                icon-color="red"
                title="这是一段内容确定删除吗？"
            >
              <el-button size="mini" type="danger" slot="reference" icon="el-icon-delete"
                         @click.native.stop="itemBtnClick(obj.row)"></el-button>
            </el-popconfirm>


          </template>
        </el-table-column>
      </el-table>
      <!--    分页部分-->
      <div class="page-box">
        <el-pagination
            background
            :current-page="searchForm.currentPage"
            :page-size="searchForm.pageSize"
            @current-change="pageChangeHandler"
            layout="prev, pager, next"
            :total="total">
        </el-pagination>
      </div>
    </el-scrollbar>


    <!--    弹框-->

    <el-dialog title="操作实体" :visible.sync="editDialog" width="35%">
      <!---->
      <el-form ref="form" :model="formData" :rules="formRules" label-width="80px" size="mini">

        <el-form-item label="上级菜单" prop="parentId">
          <treeselect v-model="formData.parentId" :options="parentList" :show-count="true" :normalizer="normalizer"/>
        </el-form-item>

        <el-form-item label="权限类型" prop="menuType">
          <el-radio-group v-model="formData.menuType" size="mini">
            <el-radio-button :label="0">目录</el-radio-button>
            <el-radio-button :label="1">菜单</el-radio-button>
            <el-radio-button :label="2">按钮</el-radio-button>
          </el-radio-group>

        </el-form-item>

        <el-form-item label="菜单图标" prop="menuIcon" v-if="formData.menuType!=2">
          <e-icon-picker v-model="formData.menuIcon" :highLightColor="highLightColor" :options="options"
                         :zIndex="zIndex"/>
        </el-form-item>

        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="菜单名称" prop="menuTitle">
              <el-input v-model="formData.menuTitle"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="菜单排序" prop="sort">
              <el-input-number v-model="formData.sort" controls-position="right" :min="1"
                               style="width: 100%"></el-input-number>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="路由地址" prop="routerPath" v-if="formData.menuType!=2">
              <el-input v-model="formData.routerPath"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">

            <el-form-item label="组件地址" prop="component" v-if="formData.menuType==1">
              <el-input v-model="formData.component"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="12">

            <el-form-item label="权限标识" prop="permSign" v-if="formData.menuType!=0">
              <el-input v-model="formData.permSign"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
          </el-col>
        </el-row>


      </el-form>


      <div slot="footer" class="dialog-footer">
        <el-button @click="editDialog = false" size="mini">取 消</el-button>
        <el-button type="primary" size="mini" @click="addOrEdit">确 定</el-button>
      </div>
    </el-dialog>


  </div>
</template>

<script src="./index.js">
</script>

<style src="./index.scss" lang="scss">

</style>
